package dataBase;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
/**
 * 
 * @author mahanlei 
 * @time 2016/11/19
 *通用的连接数据库的类
 */
public class JdbcUtils {
   private static String DRIVER_CLASS="";
   private static String URL="";
   private static String USER="";
   private static String PASSWORD="";
   static{
	   ResourceBundle rBundle=ResourceBundle.getBundle("dbc.properties");
	   DRIVER_CLASS=rBundle.getString("driverClass");
	   URL=rBundle.getString("url");
	   USER=rBundle.getString("user");
	   PASSWORD=rBundle.getString("password");
	   
	   
	   try {
		Class.forName(DRIVER_CLASS);
	} catch (ClassNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
   }
   public static Connection getConnection(){
	   try {
		return (Connection) DriverManager.getConnection(URL,USER,PASSWORD);
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	   return null;
   }
   public static void release(ResultSet rs,Statement s,Connection c){
	   if(rs!=null){
		   try {
			rs.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	   }
	   if(s!=null){
			try {
				s.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
	   }
	   if(c!=null){
			try {
				c.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
	   }
	   
   }
}
